package org.example.service.impl;


import org.example.controller.Code;
import org.example.dao.FoodDao;
import org.example.domain.Food;
import org.example.exception.SystemException;
import org.example.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class FoodServiceImpl  implements FoodService {
    @Autowired
    private FoodDao foodDao;

    @Override
    public boolean save(Food food) {
        foodDao.save(food);
        return true;
    }

    @Override
    public boolean update(Food food) {
        foodDao.update(food);
        return true;
    }

    @Override
    public boolean delete(Integer id) {
        foodDao.delete(id);
        return true;
    }

    @Override
    public Food findById(Integer id) {
//        if (id == 1){
//            throw new SystemException("查询id为一的记录异常", Code.SYSTEM_ERR);
//        }
//        try {  int i = 1/0;
//        } catch (Exception e) {
//            throw new SystemException("系统异常，请稍后再试", Code.SYSTEM_ERR);
//        }

        return foodDao.findById(id);
    }

    @Override
    public List<Food> findAll() {
        return foodDao.findAll();

    }
}
